{extend name="index/layout" /}

{block name="canonical"}
<link rel="canonical" href="https://{$site_domain}/">
{/block}

{block name="content"}
    <!-- 横幅区域 -->
    <div class="relative rounded-lg overflow-hidden mb-8">
        <div class="relative z-10 py-16 px-8 md:px-16 text-white">
            <h1 class="text-3xl md:text-5xl font-bold mb-4 animate-fadeIn text-center">高清電腦桌布，手機桌布</h1>
            <p class="text-xl md:text-2xl mb-8 animate-fadeIn text-center" style="animation-delay: 0.2s;">桌布產生器-輸入任意內容，產生你的專屬桌布</p>
            <div class="ai-wallpaper-generator animate-fadeIn" style="animation-delay: 0.4s;">
                <div class="generator-container">
                    <div class="input-container">
                        <textarea id="promptText" placeholder="輸入您想要的桌布描述，例如：星空下的湖泊、未來科技城市..." class="w-full p-4 rounded-lg border border-primary focus:outline-none focus:ring-2 focus:ring-primary"></textarea>
                        <div class="mt-3 flex items-center">
                            <label class="text-white font-medium mr-3 whitespace-nowrap">桌布類型：</label>
                            <div class="type-selector flex space-x-2">
                                <button id="mobileType" class="type-btn type-active flex items-center px-3 py-1.5 rounded-full text-sm">
                                    <i class="fas fa-mobile-alt mr-1"></i> 手機桌布
                                </button>
                                <button id="desktopType" class="type-btn flex items-center px-3 py-1.5 rounded-full text-sm">
                                    <i class="fas fa-desktop mr-1"></i> 電腦桌布
                                </button>
                            </div>
                        </div>
                        
                        <div class="mt-3 flex items-center">
                            <label class="text-white font-medium mr-3 whitespace-nowrap">清晰度：</label>
                            <div class="quality-selector flex space-x-2">
                                <button id="defaultQuality" class="quality-btn quality-active flex items-center px-3 py-1.5 rounded-full text-sm">
                                    <i class="fas fa-image mr-1"></i> 默認
                                </button>
                                <button id="hdQuality" class="quality-btn flex items-center px-3 py-1.5 rounded-full text-sm" {if $user_info.user_type == 'guest'}disabled{/if}>
                                    <i class="fas fa-crown mr-1"></i> 高清
                                </button>
                                <button id="4kQuality" class="quality-btn flex items-center px-3 py-1.5 rounded-full text-sm" disabled>
                                    <i class="fas fa-gem mr-1"></i> 4K
                                </button>
                            </div>
                            {if $user_info.user_type == 'guest'} 
                            <div class="ml-3 text-xs text-amber-300 flex items-center">
                                <i class="fas fa-lock mr-1"></i> 
                                <span>綁定Google帳號解鎖高清選項</span>
                            </div>
                            {/if}
                        </div>
                        
                        <!-- 使用次数显示 -->
                        <div class="mt-3 flex items-center justify-between">
                            <div class="text-sm text-white">
                                <i class="fas fa-bolt text-yellow-400 mr-1"></i> 
                                今日已使用：<span id="usedLimitDisplay">{$used_limit}</span>/<span id="dailyLimitDisplay">{$daily_limit}</span> 次
                            </div>
                            {if $user_info.user_type == 'guest'}
                            <div class="text-xs text-amber-300">
                                <i class="fas fa-info-circle mr-1"></i>
                                綁定Google帳號可獲得更多次數
                            </div>
                            {/if}
                        </div>
                        
                        <button id="generateBtn" class="generate-btn w-full mt-4 py-3 rounded-lg text-white font-bold">
                            <i class="fas fa-magic mr-2"></i> 生成桌布
                        </button>
                    </div>
                    <div id="resultContainer" class="result-container hidden">
                        <div id="imageWrapper" class="image-wrapper relative">
                            <img id="generatedImage" src="" alt="生成的桌布" class="w-full rounded-lg shadow-lg max-h-[80vh] object-contain">
                            <div id="mobileFrameContainer" class="mobile-frame-container hidden">
                                <div class="mobile-frame"></div>
                            </div>
                            <div class="img-loading-overlay">
                                <div class="img-spinner"></div>
                            </div>
                        </div>
                        <div class="action-buttons mt-4 flex space-x-3">
                            <button id="previewBtn" class="preview-btn flex-1 py-3 rounded-lg text-white font-bold hidden" disabled>
                                <i class="fas fa-eye-slash mr-2 preview-icon"></i> 預覽
                            </button>
                            <button id="downloadBtn" class="download-btn flex-1 py-3 rounded-lg text-white font-bold" disabled>
                                <i class="fas fa-download mr-2"></i> 下載
                            </button>
                            <button id="regenerateBtn" class="regenerate-btn flex-1 py-3 rounded-lg text-white font-bold" disabled>
                                <i class="fas fa-sync-alt mr-2"></i> 换一张
                            </button>
                            <button id="restartBtn" class="restart-btn flex-1 py-3 rounded-lg text-white font-bold" disabled>
                                <i class="fas fa-pencil-alt mr-2"></i> 重新輸入
                            </button>
                        </div>
                        
                        <!-- 结果界面使用次数显示 -->
                        <div class="mt-3 flex items-center justify-between">
                            <div class="text-sm text-white">
                                <i class="fas fa-bolt text-yellow-400 mr-1"></i> 
                                今日已使用：<span id="resultUsedLimitDisplay">{$used_limit}</span>/<span id="resultDailyLimitDisplay">{$daily_limit}</span> 次
                            </div>
                            {if $user_info.user_type == 'guest'}
                            <div class="text-xs text-amber-300">
                                <i class="fas fa-info-circle mr-1"></i>
                                綁定Google帳號可獲得更多次數
                            </div>
                            {/if}
                        </div>
                    </div>
                </div>
                <div id="generatorOverlay" class="generator-overlay hidden">
                    <div class="progress-container">
                        <div class="progress-bar">
                            <div id="progressBar" class="progress-fill"></div>
                        </div>
                        <div class="progress-text">
                            <span id="progressText">0%</span> - <span id="timeLeft"></span>
                        </div>
                    </div>
                    <p class="mt-4 text-white">正在生成您的專屬桌布...</p>
                </div>
            </div>
        </div>
        <div class="absolute inset-0 banner-overlay opacity-90"></div>
    </div>
    
    <!-- 推荐桌布 - 电脑和手机 -->
    <section id="featured" class="mb-12">
        <div class="flex justify-between items-center mb-6">
            <h2 class="text-2xl font-bold text-primary">推薦桌布</h2>
            <div class="flex space-x-6">
                <button id="desktop-tab" class="tab-button active text-lg font-medium">
                    <i class="fas fa-desktop mr-2"></i> 電腦桌布
                </button>
                <button id="mobile-tab" class="tab-button text-lg font-medium">
                    <i class="fas fa-mobile-alt mr-2"></i> 手機桌布
                </button>
            </div>
        </div>
        
        <!-- 电脑桌布推荐 -->
        <div id="featured-desktop" class="tab-content active">
            <div class="flex justify-between items-center mb-4">
                <p class="text-gray-600">精選高清電腦桌布，適合各種螢幕尺寸</p>
                <a href="/featured/<?php echo rawurlencode('電腦桌布')?>/" class="text-accent hover:underline">
                    查看更多 <i class="fas fa-chevron-right ml-1"></i>
                </a>
            </div>
            <div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
                {volist name="featuredDesktopWallpapers" id="wallpaper"}
                <div class="bg-white rounded-lg shadow-md overflow-hidden hover-card">
                    <a href="/category/{:$wallpaper.type == 'mobile' ? rawurlencode('手機桌布') : rawurlencode('電腦桌布')}/{$wallpaper.category_name|rawurlencode}/{$wallpaper.title|rawurlencode}">
                        <div class="relative bg-gray-200 desktop-card">
                            <img src="{$wallpaper.show_file_path}" alt="{$wallpaper.title}" class="w-full h-full object-cover lazy" loading="lazy">
                            <div class="absolute bottom-0 left-0 bg-primary bg-opacity-80 text-white px-3 py-1 text-sm">
                                <i class="fas fa-eye mr-1"></i> {$wallpaper.view_cnt}
                                <i class="fas fa-download ml-3 mr-1"></i> {$wallpaper.download_cnt}
                            </div>
                            <div class="absolute top-0 right-0 bg-secondary text-white px-2 py-1 text-xs rounded-tl-md">
                                <a href="/category/{:$wallpaper.type == 'mobile' ? rawurlencode('手機桌布') : rawurlencode('電腦桌布')}/{$wallpaper.category_name|rawurlencode}">{$wallpaper.category_name}</a>
                            </div>
                        </div>
                        <div class="p-4">
                            <h3 class="text-lg font-bold mb-2 text-primary truncate">{$wallpaper.title}</h3>
                        </div>
                    </a>
                </div>
                {/volist}
            </div>
        </div>
        
        <!-- 手机桌布推荐 -->
        <div id="featured-mobile" class="tab-content">
            <div class="flex justify-between items-center mb-4">
                <p class="text-gray-600">精選高清手機桌布，完美適配各種手機型號</p>
                <a href="/featured/<?php echo rawurlencode('手機桌布')?>/" class="text-accent hover:underline">
                    查看更多 <i class="fas fa-chevron-right ml-1"></i>
                </a>
            </div>
            <div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4">
                {volist name="featuredMobileWallpapers" id="wallpaper"}
                <div class="bg-white rounded-lg shadow-md overflow-hidden hover-card">
                    <a href="/category/{:$wallpaper.type == 'mobile' ? rawurlencode('手機桌布') : rawurlencode('電腦桌布')}/{$wallpaper.category_name|rawurlencode}/{$wallpaper.title|rawurlencode}">
                        <div class="relative bg-gray-200 mobile-card">
                            <img src="{$wallpaper.show_file_path}" alt="{$wallpaper.title}" class="w-full h-full object-cover lazy" loading="lazy">
                        </div>
                        <div class="p-3">
                            <h3 class="text-sm font-bold mb-1 text-primary truncate">{$wallpaper.title}</h3>
                            <div class="flex justify-between items-center text-xs text-gray-500">
                                <span><i class="fas fa-eye mr-1"></i> {$wallpaper.view_cnt}</span>
                                <span><i class="fas fa-download mr-1"></i> {$wallpaper.download_cnt}</span>
                            </div>
                        </div>
                    </a>
                </div>
                {/volist}
            </div>
        </div>
    </section>
    
    <!-- 最新桌布 -->
    <section class="mb-12">
        <div class="flex justify-between items-center mb-6">
            <h2 class="text-2xl font-bold text-primary">最新桌布</h2>
            <div class="flex space-x-6">
                <button id="latest-desktop-tab" class="tab-button active text-lg font-medium">
                    <i class="fas fa-desktop mr-2"></i> 電腦桌布
                </button>
                <button id="latest-mobile-tab" class="tab-button text-lg font-medium">
                    <i class="fas fa-mobile-alt mr-2"></i> 手機桌布
                </button>
            </div>
        </div>
        
        <!-- 电脑最新桌布 -->
        <div id="latest-desktop-content" class="tab-content active">
            <div class="flex justify-between items-center mb-4">
                <p class="text-gray-600">最新上傳的高清電腦桌布</p>
                <a href="/category/<?php echo rawurlencode('電腦桌布')?>/" class="text-accent hover:underline">
                    查看更多 <i class="fas fa-chevron-right ml-1"></i>
                </a>
            </div>
            <div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
                {volist name="latestDesktopWallpapers" id="wallpaper"}
                <div class="bg-white rounded-lg shadow-md overflow-hidden hover-card">
                    <a href="/category/{:rawurlencode('電腦桌布')}/{$wallpaper.category_name|rawurlencode}/{$wallpaper.title|rawurlencode}">
                        <div class="relative bg-gray-200 desktop-card">
                            <img src="{$wallpaper.show_file_path}" alt="{$wallpaper.title}" class="w-full h-full object-cover lazy" loading="lazy">
                            <div class="absolute bottom-0 left-0 bg-secondary text-white px-2 py-1 text-xs rounded-tl-md">
                                <a href="/category/{:rawurlencode('電腦桌布')}/{$wallpaper.category_name|rawurlencode}">{$wallpaper.category_name}</a>
                            </div>
                        </div>
                        <div class="p-3">
                            <h3 class="text-md font-bold mb-2 text-primary truncate">{$wallpaper.title}</h3>
                            <div class="flex flex-wrap gap-1 tag-cloud">
                                {volist name="wallpaper.tags" id="tag" length="3"}
                                {if $tag != ''}
                                <span class="text-xs">{$tag}</span>
                                {/if}
                                {/volist}
                            </div>
                        </div>
                    </a>
                </div>
                {/volist}
            </div>
        </div>
        
        <!-- 手机最新桌布 -->
        <div id="latest-mobile-content" class="tab-content">
            <div class="flex justify-between items-center mb-4">
                <p class="text-gray-600">最新上傳的高清手機桌布</p>
                <a href="/category/<?php echo rawurlencode('手機桌布')?>/" class="text-accent hover:underline">
                    查看更多 <i class="fas fa-chevron-right ml-1"></i>
                </a>
            </div>
            <div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4">
                {volist name="latestMobileWallpapers" id="wallpaper"}
                <div class="bg-white rounded-lg shadow-md overflow-hidden hover-card">
                    <a href="/category/{:rawurlencode('手機桌布')}/{$wallpaper.category_name|rawurlencode}/{$wallpaper.title|rawurlencode}">
                        <div class="relative bg-gray-200 mobile-card">
                            <img src="{$wallpaper.show_file_path}" alt="{$wallpaper.title}" class="w-full h-full object-cover lazy" loading="lazy">
                            <div class="absolute bottom-0 left-0 bg-secondary text-white px-2 py-1 text-xs rounded-tl-md">
                                <a href="/category/{:rawurlencode('手機桌布')}/{$wallpaper.category_name|rawurlencode}">{$wallpaper.category_name}</a>
                            </div>
                        </div>
                        <div class="p-3">
                            <h3 class="text-md font-bold mb-2 text-primary truncate">{$wallpaper.title}</h3>
                            <div class="flex flex-wrap gap-1 tag-cloud">
                                {volist name="wallpaper.tags" id="tag" length="3"}
                                {if $tag != ''}
                                <span class="text-xs">{$tag}</span>
                                {/if}
                                {/volist}
                            </div>
                        </div>
                    </a>
                </div>
                {/volist}
            </div>
        </div>
    </section>
    
    <!-- 热门桌布 - 电脑和手机 -->
    <section class="mb-12">
        <div class="flex justify-between items-center mb-6">
            <h2 class="text-2xl font-bold text-primary">熱門下載</h2>
            <div class="flex space-x-6">
                <button id="popular-desktop-tab" class="tab-button active text-lg font-medium">
                    <i class="fas fa-desktop mr-2"></i> 電腦桌布
                </button>
                <button id="popular-mobile-tab" class="tab-button text-lg font-medium">
                    <i class="fas fa-mobile-alt mr-2"></i> 手機桌布
                </button>
            </div>
        </div>
        
        <!-- 电脑热门桌布 -->
        <div id="popular-desktop-content" class="tab-content active">
            <div class="flex justify-between items-center mb-4">
                <p class="text-gray-600">最受歡迎的電腦桌布</p>
                <a href="/popular/<?php echo rawurlencode('電腦桌布')?>/" class="text-accent hover:underline">
                    查看更多 <i class="fas fa-chevron-right ml-1"></i>
                </a>
            </div>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                {volist name="popularDesktopWallpapers" id="wallpaper" length="4"}
                <div class="flex bg-white rounded-lg shadow-md overflow-hidden h-32 hover-card">
                    <div class="w-1/3 bg-gray-200">
                        <img src="{$wallpaper.show_file_path}" alt="{$wallpaper.title}" class="w-full h-full object-cover lazy" loading="lazy">
                    </div>
                    <div class="w-2/3 p-4 flex flex-col justify-between">
                        <div>
                            <h3 class="text-lg font-bold text-primary truncate">{$wallpaper.title}</h3>
                            <p class="text-sm text-gray-500">
                                <span class="inline-block mr-2"><i class="fas fa-desktop text-primary"></i> 電腦桌布</span>
                                <span>{$wallpaper.category_name}</span>
                            </p>
                        </div>
                        <div class="flex justify-between items-center">
                            <div class="text-sm text-gray-600">
                                <i class="fas fa-download mr-1"></i> {$wallpaper.download_cnt}
                            </div>
                            <a href="/category/{:$wallpaper.type == 'mobile' ? rawurlencode('手機桌布') : rawurlencode('電腦桌布')}/{$wallpaper.category_name|rawurlencode}/{$wallpaper.title|rawurlencode}" class="text-accent hover:underline text-sm">
                                查看詳情 <i class="fas fa-arrow-right ml-1"></i>
                            </a>
                        </div>
                    </div>
                </div>
                {/volist}
            </div>
        </div>
        
        <!-- 手机热门桌布 -->
        <div id="popular-mobile-content" class="tab-content">
            <div class="flex justify-between items-center mb-4">
                <p class="text-gray-600">最受歡迎的手機桌布</p>
                <a href="/popular/<?php echo rawurlencode('手機桌布')?>/" class="text-accent hover:underline">
                    查看更多 <i class="fas fa-chevron-right ml-1"></i>
                </a>
            </div>
            <div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4">
                {volist name="popularMobileWallpapers" id="wallpaper"}
                <div class="bg-white rounded-lg shadow-md overflow-hidden hover-card">
                    <a href="/category/{:$wallpaper.type == 'mobile' ? rawurlencode('手機桌布') : rawurlencode('電腦桌布')}/{$wallpaper.category_name|rawurlencode}/{$wallpaper.title|rawurlencode}">
                        <div class="relative bg-gray-200 mobile-card">
                            <img src="{$wallpaper.show_file_path}" alt="{$wallpaper.title}" class="w-full h-full object-cover lazy" loading="lazy">
                            <div class="absolute bottom-0 left-0 right-0 bg-accent bg-opacity-80 text-white px-2 py-1 text-sm text-center">
                                <i class="fas fa-download mr-1"></i> {$wallpaper.download_cnt}
                            </div>
                        </div>
                        <div class="p-3">
                            <h3 class="text-sm font-bold mb-1 text-primary truncate">{$wallpaper.title}</h3>
                            <p class="text-xs text-gray-500 truncate">{$wallpaper.category_name}</p>
                        </div>
                    </a>
                </div>
                {/volist}
            </div>
        </div>
    </section>
    
    <!-- 分类导航 -->
    <section>
        <div class="flex justify-between items-center mb-6">
            <h2 class="text-2xl font-bold text-primary">分類瀏覽</h2>
        </div>
        <div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-4">
            {volist name="categories" id="category" length="8"}
            <div class="bg-white rounded-lg shadow-md overflow-hidden hover-card">
                <div class="flex">
                    <a href="/category/<?php echo rawurlencode('電腦桌布')?>/{$category.name|rawurlencode}/" class="w-1/2 py-4 text-center hover:bg-light transition duration-300 border-r">
                        <div class="text-2xl mb-2">
                            <i class="fas fa-desktop category-icon cat-{$category.id}"></i>
                        </div>
                        <div class="text-sm font-bold text-primary">電腦</div>
                    </a>
                    <a href="/category/<?php echo rawurlencode('手機桌布')?>/{$category.name|rawurlencode}/" class="w-1/2 py-4 text-center hover:bg-light transition duration-300">
                        <div class="text-2xl mb-2">
                            <i class="fas fa-mobile-alt category-icon cat-{$category.id}"></i>
                        </div>
                        <div class="text-sm font-bold text-primary">手機</div>
                    </a>
                </div>
                <div class="bg-gray-100 p-3 text-center">
                    <h3 class="text-lg font-bold text-primary">{$category.name}</h3>
                </div>
            </div>
            {/volist}
        </div>
    </section>
{/block}

{block name="script"}
<script>
    // 加载预计时间配置
    var loadingTimeConfig = {$loading_time};
    var daily_limit = {$daily_limit};
    var used_limit = {$used_limit};
</script>
<script src="/static/js/index.js?v=11"></script>
{/block} 